package com.stmt.analytic.graph.algorithm;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Id-mapping
 */
public class IdMapping {

    String[] from;

    Map<String, Integer> to;

    int currentId;


    public IdMapping(int size) {
        from = new String[size];
        to = new HashMap<>(size);
    }

    public int add(String oid) {
        synchronized (this) {
            from[currentId] = oid;
            to.put(oid, currentId);
        }
        return currentId++;
    }

    public String toOriginalId(int id) {
        return from[id];
    }

    public int toMappedId(String oid) {
        return to.getOrDefault(oid, -1);
    }

    public int nodeCount() {
        return currentId;
    }
}
